package com.chee.plant.hibernate.dao;

import org.hibernate.Query;
import org.hibernate.Session;

import com.chee.plant.hibernate.object.UserPlant;
import com.chee.plant.server.HibernateSessionFactory;

public class UserPlantDAO extends BaseHibernateDAO {

	/**
	 * 根据用户普通植物Id查询用户普通植物
	 * 
	 * @param id
	 *            用户普通植物Id
	 * @return 特定的用户普通植物
	 */
	public UserPlant getUserPlantById(Integer id) {
		Session session = HibernateSessionFactory.getSession();
		String hql = "select userPlant from UserPlant as userPlant where userPlant.Id=:id";
		Query query = session.createQuery(hql);
		query.setInteger("id", id);
		return (UserPlant) query.uniqueResult();

	}

	/**
	 * 主方法，用于测试
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// 1 测试getUserPlantById(Integer id)
		UserPlant userPlant = new UserPlantDAO().getUserPlantById(1);
		System.out.println(userPlant.getLife());
		System.out.println(userPlant.getPlantId());
		System.out.println(userPlant.getStatus());

	}

}
